//
//  UIImageView+SimpleWebImage.m
//  SimpleWebImage
//
//  Created by Jiang on 2019/8/27.
//  Copyright © 2019 SilverFruity. All rights reserved.
//

#import "UIImageView+SimpleWebImage.h"
#import "SimpleWebImageManager.h"
#import <objc/runtime.h>
@implementation UIImageView (SimpleWebImage)
- (SimpleImageOperation *)simpleWebImageOperator{
   return objc_getAssociatedObject(self, _cmd);
}
- (void)setSimpleWebImageOperator:(SimpleImageOperation *)simpleWebImageOperator{
    objc_setAssociatedObject(self, NSSelectorFromString(@"simpleWebImageOperator"), simpleWebImageOperator, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)sp_setImageWithURL:(NSURL *)url{
    [self sp_setImageWithURL:url placholder:nil];
}
- (void)sp_setImageWithURL:(NSURL *)url placholder:(UIImage *)placholder{
    self.image = placholder;
    [self simpleWebImageOperator].isCancel = YES;
    self.simpleWebImageOperator = [[SimpleWebImageManager shareInstance] loadImageWithUrl:url progress:nil complete:^(UIImage * _Nonnull image, NSURL * _Nonnull url, NSError * _Nullable error) {
        if (image) self.image = image;
    }];
}
@end
